import MathUtil from '@/MathUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import SLKCommon from 'code/Core/Common/SLKCommon';
import UnitCommon from 'code/Core/Common/UnitCommon';
import AbilityBase from 'code/Scripts/Abilities/base/AbilityBase';
/**
 * 散射
 **/
export default class YX_SplitShoot extends AbilityBase {
    static instance: YX_SplitShoot;
    constructor(id: string = 'Ass1') {
        super(id);
        YX_SplitShoot.instance = this;
        this.init();
        se.onUnitSpellEffect(this.onSpellEffect.bind(this), this.id);
    }
    init() {}
    cast<T extends Object = any>(tarX: number, tarY: number, source: unit, target: unit, data?: T): void {
        let missile = SLKCommon.getUnitMissileart(source);
        let speed = SLKCommon.getUnitMissileSpeed(source) * 2;
        let fa = MathUtil.angleBetweenCoords(GetUnitX(source), GetUnitY(source), tarX, tarY);
        for (let i = -2; i < 3; i++) {
            let angle = fa + i * 10;
            MovementCommon.LineMissile({
                speed,
                missile,
                caster: source,
                radius: 50,
                angle,
                distance: 600,
                onHit: this.onMissileHit.bind(this),
            });
        }
    }
    onSpellEffect() {
        this.cast(GetSpellTargetX(), GetSpellTargetY(), GetTriggerUnit(), GetSpellTargetUnit());
    }
    onMissileHit(p: LineMissileConfig, hitBody: unit) {
        let lv = this.getAbilityLevel(p.caster);
        let dmg = 50 * lv + UnitCommon.取攻击(p.caster) * (0.5 + 0.5 * lv);
        DamageSystemInstance.applyAttackDamage(hitBody, p.caster, dmg, this.id);
    }
}
